/*
* Copyright (c) 2020 - 2025 Renesas Electronics Corporation and/or its affiliates
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include "hw_sce_ra_private.h"

void HW_SCE_p_func402_r1(void)
{
    WR1_PROG(REG_1600H, 0x38000c00U);
    WR1_PROG(REG_1608H, 0x00000080U);
    WR1_PROG(REG_143CH, 0x00260000U);

    HW_SCE_p_func100(0x3f19e947U, 0x461b8419U, 0xd01fd45cU, 0x86cf05bcU);
    WR1_PROG(REG_143CH, 0x00400000U);

    if (CHCK_STS(REG_143CH, 22, 1))
    {
        WR1_PROG(REG_1014H, 0x00000b60U);
        WR1_PROG(REG_1018H, 0x00000b10U);
        WR1_PROG(REG_1020H, 0x00000750U);

        WR1_PROG(REG_1004H, 0x0404000aU);
        WR1_PROG(REG_1000H, 0x00010001U);
        WAIT_STS(REG_1000H, 0, 0);

        WR1_PROG(REG_1014H, 0x00000bb0U);
        WR1_PROG(REG_1018H, 0x00000b10U);
        WR1_PROG(REG_1020H, 0x000007a0U);

        WR1_PROG(REG_1004H, 0x0404000aU);
        WR1_PROG(REG_1000H, 0x00010001U);
        WAIT_STS(REG_1000H, 0, 0);

        WR1_PROG(REG_1014H, 0x00000c00U);
        WR1_PROG(REG_1018H, 0x00000b10U);
        WR1_PROG(REG_1020H, 0x000007f0U);

        WR1_PROG(REG_1004H, 0x0404000aU);
        WR1_PROG(REG_1000H, 0x00010001U);
        WAIT_STS(REG_1000H, 0, 0);

        HW_SCE_p_func101(0x01e49c68U, 0xdc6ef63bU, 0x363973ebU, 0x7decb592U);
    }
    else
    {
        WR1_PROG(REG_1014H, 0x00000480U);
        WR1_PROG(REG_1018H, 0x00000b10U);
        WR1_PROG(REG_1020H, 0x00000750U);

        WR1_PROG(REG_1004H, 0x0404000aU);
        WR1_PROG(REG_1000H, 0x00010001U);
        WAIT_STS(REG_1000H, 0, 0);

        WR1_PROG(REG_1014H, 0x000004d0U);
        WR1_PROG(REG_1018H, 0x00000b10U);
        WR1_PROG(REG_1020H, 0x000007a0U);

        WR1_PROG(REG_1004H, 0x0404000aU);
        WR1_PROG(REG_1000H, 0x00010001U);
        WAIT_STS(REG_1000H, 0, 0);

        WR1_PROG(REG_1014H, 0x00000520U);
        WR1_PROG(REG_1018H, 0x00000b10U);
        WR1_PROG(REG_1020H, 0x000007f0U);

        WR1_PROG(REG_1004H, 0x0404000aU);
        WR1_PROG(REG_1000H, 0x00010001U);
        WAIT_STS(REG_1000H, 0, 0);

        HW_SCE_p_func101(0x126487c8U, 0x96e30532U, 0x401683b1U, 0x29742279U);
    }

    WR1_PROG(REG_1600H, 0x00007c1dU);
    WR1_PROG(REG_143CH, 0x00602000U);
    WR1_PROG(REG_1458H, 0x00000000U);
}
